package com.lrkj.payfee.service.impl;

import java.util.List;

import com.lrkj.common.exception.BaseException;
import com.lrkj.common.utils.DateUtils;
import com.lrkj.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lrkj.payfee.mapper.PaymentItemsMapper;
import com.lrkj.payfee.domain.PaymentItems;
import com.lrkj.payfee.service.IPaymentItemsService;

/**
 * 付款项目Service业务层处理
 *
 * @author yajun_ren
 * @date 2022-03-21
 */
@Service
public class PaymentItemsServiceImpl implements IPaymentItemsService {
    @Autowired
    private PaymentItemsMapper paymentItemsMapper;

    /**
     * 查询付款项目
     *
     * @param id 付款项目ID
     * @return 付款项目
     */
    @Override
    public PaymentItems selectPaymentItemsById(String id) {
        return paymentItemsMapper.selectPaymentItemsById(id);
    }

    /**
     * 查询付款项目列表
     *
     * @param paymentItems 付款项目
     * @return 付款项目
     */
    @Override
    public List<PaymentItems> selectPaymentItemsList(PaymentItems paymentItems) {
        return paymentItemsMapper.selectPaymentItemsList(paymentItems);
    }

    /**
     * 新增付款项目
     *
     * @param paymentItems 付款项目
     * @return 结果
     */
    @Override
    public int insertPaymentItems(PaymentItems paymentItems) {
        try {
            paymentItems.setId(paymentItems.getCode());
            paymentItems.setCreateBy(SecurityUtils.getUsername());
            paymentItems.setCreateTime(DateUtils.getNowDate());
            paymentItemsMapper.insertPaymentItems(paymentItems);
        } catch (Exception e) {
            if (e.getMessage().indexOf("for key 'PRIMARY'") != -1) {
                throw new BaseException("代码已存在！");
            }
        }
        return 1;
    }

    /**
     * 修改付款项目
     *
     * @param paymentItems 付款项目
     * @return 结果
     */
    @Override
    public int updatePaymentItems(PaymentItems paymentItems) {
        try {
            paymentItems.setUpdateBy(SecurityUtils.getUsername());
            paymentItems.setUpdateTime(DateUtils.getNowDate());
            paymentItemsMapper.updatePaymentItems(paymentItems);
        } catch (Exception e) {
            if (e.getMessage().indexOf("for key 'PRIMARY'") != -1) {
                throw new BaseException("代码已存在！");
            }
        }
        return 1;
    }

    /**
     * 批量删除付款项目
     *
     * @param ids 需要删除的付款项目ID
     * @return 结果
     */
    @Override
    public int deletePaymentItemsByIds(String[] ids) {
        return paymentItemsMapper.deletePaymentItemsByIds(ids);
    }

    /**
     * 删除付款项目信息
     *
     * @param id 付款项目ID
     * @return 结果
     */
    @Override
    public int deletePaymentItemsById(String id) {
        return paymentItemsMapper.deletePaymentItemsById(id);
    }

    /**
     * 批量新增付款项目信息
     *
     * @param paymentItemss 付款项目对象
     */
    public int batchAddData(List<PaymentItems> paymentItemss) {
        return paymentItemsMapper.batchAddData(paymentItemss);
    }
}
